package com.action.school;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.action.base.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.pageModel.Donate;
import com.pageModel.Json;
import com.service.school.DonateServiceI;

/**
 * 捐赠ACTION
 * 
 * @author chenq
 * 
 */

@Namespace("/school")
@Action(value = "donateAction")
public class DonateAction extends BaseAction implements ModelDriven<Donate> {

	Donate donate = new Donate();

	@Override
	public Donate getModel() {
		return donate;
	}

	private DonateServiceI DonateService;

	public DonateServiceI getDonateService() {
		return DonateService;
	}

	@Autowired
	public void setDonateService(DonateServiceI donateService) {
		DonateService = donateService;
	}

	public void datagrid() {
		super.writeJson(DonateService.datagrid(donate));
	}

	public void remove() {
		DonateService.remove(donate.getIds());
		Json j = new Json();
		j.setSuccess(true);
		j.setMsg("删除成功！");
		super.writeJson(j);
	}

	public void add() {
		String json = null;
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			DonateService.add(donate);
			m.put("success", true);
			m.put("msg", "添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			m.put("success", false);
			m.put("msg", "添加失败！");
			System.out.print(e.getMessage());
		}
		super.writeJson(m);
	}

	public void edit() {
		DonateService.edit(donate);
		Json j=new Json();
		j.setSuccess(true);
		j.setMsg("修改成功！");
		super.writeJson(j);
	}
}
